package com.dublbo.addressbook.frame.group;

import com.dublbo.addressbook.frame.CPersonMainPanel;
import com.dublbo.addressbook.util.FileOperation;
import com.dublbo.jpSwing.JpToaster;
import com.dublbo.jpSwing.thread.JpShortTask;

public class GroupUpdateTask extends JpShortTask {
    private CPersonMainPanel ui;
    private String rawGroupName;
    private String modifyGroupName;

    public GroupUpdateTask(CPersonMainPanel ui) {
        this.ui = ui;
    }

    @Override
    protected void doInBackground() throws Exception {
        this.rawGroupName = (String) this.args[0];
        this.modifyGroupName = (String) this.args[1];

        FileOperation.modifyGroupTxtFileRow(rawGroupName, modifyGroupName);
        System.out.println("已修改联系组：" + rawGroupName);
    }

    @Override
    protected void done() {
        if (this.err != null) {
            JpToaster.show(this.ui, JpToaster.ERROR, this.err.getMessage());
            return;
        }
        // 更新界面相关资源
        this.ui.left_menu.setTitleAt(this.ui.left_menu.getSelectedIndex(), modifyGroupName);
        this.ui.groupFilter = modifyGroupName;
    }
}
